﻿using Himp.TaskScheduling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace Himp.Workflows
{
    /// <summary>
    /// 流程待办任务
    /// </summary>
    public class WorkflowTodoTaskService : TaskSchedulingAppService, IWorkflowTodoTaskService
    {
        private ActiviWorkflowManager _workflowManager;

        public WorkflowTodoTaskService(ActiviWorkflowManager workflowManager)
        {
            _workflowManager = workflowManager;
        }

        public async Task<PagedResultDto<WorkflowTodoTaskDto>> GetListAsync(WorkflowTodoTaskInput input)
        {
            var list = await _workflowManager.GetTodoTask(input.UserId);
            var itemsDto = ObjectMapper.Map<List<WorkflowTodoTask>, List<WorkflowTodoTaskDto>>(list);

            if (input.Pi == 0)
            {
                return new PagedResultDto<WorkflowTodoTaskDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = itemsDto.Count();
                var pagedItems = itemsDto.Skip((input.Pi - 1) * input.Ps).Take(input.Ps);

                return new PagedResultDto<WorkflowTodoTaskDto>(totalCount, pagedItems.ToList());
            }
        }
    }
}
